package com.yanqu.road.dao.impl.activity.newyearbag;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.newyearbag.NewYearBagLimitConfig;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class NewYearBagLimitConfigDaoImpl extends TempDao {

    private static String getNewYearBagLimitConfigSql = "select * from `t_s_activity_newyearbag_limit` where `activityId`=? order by `userLv` asc";

    public List<NewYearBagLimitConfig> getNewYearBagLimitConfigList(int activityId) {
        List<NewYearBagLimitConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getNewYearBagLimitConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                NewYearBagLimitConfig newYearBagLimitConfig = new NewYearBagLimitConfig();
                newYearBagLimitConfig.setActivityId(rs.getInt("activityId"));
                newYearBagLimitConfig.setUserLv(rs.getInt("userLv"));
                newYearBagLimitConfig.setUserCondition(rs.getInt("userCondition"));

                newYearBagLimitConfig.setTongBaoDayLimit(StringUtils.stringToLongList(rs.getString("tongbaoDayLimit"), "\\|"));
                newYearBagLimitConfig.setCashDayLimit(StringUtils.stringToLongList(rs.getString("cashDayLimit"), "\\|"));
                newYearBagLimitConfig.setSkinDayLimit(StringUtils.stringToLongList(rs.getString("skinDayLimit"), "\\|"));

                newYearBagLimitConfig.setTongBaoAllLimit(rs.getInt("tongbaoAllLimit"));
                newYearBagLimitConfig.setCashAllLimit(rs.getInt("cashAllLimit"));
                newYearBagLimitConfig.setSkinAllLimit(rs.getInt("skinAllLimit"));

                newYearBagLimitConfig.setTongBaoChangeWeight(rs.getString("tongbaoChangeWeight"));
                newYearBagLimitConfig.setCashChangeWeight(rs.getString("cashChangeWeight"));
                newYearBagLimitConfig.setSkinChangeWeight(rs.getString("skinChangeWeight"));

                list.add(newYearBagLimitConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
